package com.hspedu.homework;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/10
 * @time 18:16
 */
public class Homework02 {
    public static void main(String[] args) {
        Car car = new Car("宝马",400000);
        Car car2 = new Car("宾利",5000000);

        List list = new ArrayList();
        list.add(car);
        list.add(car2);
        list.add(car2);
        list.remove(car2);

        System.out.println(list.contains(car));

        System.out.println(list.size());

        System.out.println(list.isEmpty());

        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println(next);
        }

        for (Object o : list) {
            System.out.println(o);
        }

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        list.clear();

        ArrayList arrayList = new ArrayList();
        arrayList.add(car);
        arrayList.add(car2);
        list.addAll(arrayList);

        list.containsAll(arrayList);

        list.removeAll(arrayList);


    }
}

class Car{
    private String name;
    private double price;

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    public Car(String name, double price) {
        this.name = name;
        this.price = price;
    }
}
